(function(angular){
	//创建模块
	var app = angular.module('pdlApp',[]);
	//过滤器
	app.filter('trustHtml', function ($sce) {
    return function (input) {
        return $sce.trustAsHtml(input);
    }
});
	//创建控制器
	app.controller('pdlCtrl',["$scope","$http",function($scope,$http){
		$http({
			mothed:"GET",
			url:"http://139.199.192.48:9090/api/getcategorybyid?categoryid="+location.search.slice(12)
		}).then(function(data){
			$scope.data = data.data.result[0];
			console.log(data.data.result[0]);
		});
		//获取商品列表
		$scope.page=1;
		$scope.rel="1";
		$http({
			mothed:"GET",
			url:"http://139.199.192.48:9090/api/getproductlist?categoryid="+location.search.slice(12)+"&pageid="+$scope.page
		}).then(function(datalist){
			$scope.datalist = datalist.data.result;
//			console.log(datalist.data.result);

		});
		//获取商品页数
		$http({
			mothed:"GET",
			url:"http://139.199.192.48:9090/api/getproductlist?categoryid="+location.search.slice(12)+"&pageid="+$scope.page
		}).then(function(dataCount){
			$scope.dataCount = dataCount.data;
			$scope.pageCount = Math.ceil(dataCount.data.totalCount / dataCount.data.pagesize);
			var pageCount = Math.ceil(dataCount.data.totalCount / dataCount.data.pagesize);
			var arr = [];
            for(var i=1;i<=pageCount;i++)
            {
                arr.push(i);
            }
            $scope.maxPage = arr;
//          console.log(arr.length);
		});
		//向上翻页
		$scope.upPage = function(){
			if($scope.page==1) return false;
			$scope.page--;
			$http({
				mothed:"GET",
				url:"http://139.199.192.48:9090/api/getproductlist?categoryid="+location.search.slice(12)+"&pageid="+$scope.page
			}).then(function(datalist){
				$scope.datalist = datalist.data.result;
			});
		}
		//向下翻页
		$scope.downPage = function(){
			if($scope.page==$scope.pageCount) return false;
			$scope.page++;
			$http({
				mothed:"GET",
				url:"http://139.199.192.48:9090/api/getproductlist?categoryid="+location.search.slice(12)+"&pageid="+$scope.page
			}).then(function(datalist){
				$scope.datalist = datalist.data.result;
			});
		}
		$scope.change=function(rel){
			rel=String(rel).split('/')[0];
			$http({
				mothed:"GET",
				url:"http://139.199.192.48:9090/api/getproductlist?categoryid="+location.search.slice(12)+"&pageid="+rel
			}).then(function(datalist){
				$scope.datalist = datalist.data.result;
			});
		}
	}]);
})(angular)
